﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace EncodingConverter
{
    public static class StringEncodingExtentions
    {
        public static string ConvertToUTF8(this string givenString)
        {
            StringBuilder result = new StringBuilder();
            Encoding UTF8Encoding = Encoding.UTF8;
            byte[] resultInBytes = UTF8Encoding.GetBytes(givenString);
            foreach (var currentByte in resultInBytes)
            {
                result.Append(string.Format("0x{0:X} ", currentByte));
            }
            return result.ToString();
        }

        public static string ConvertToASCII(this string givenString)
        {
            StringBuilder result = new StringBuilder();
            Encoding ASCIIEncoding = Encoding.ASCII;
            byte[] resultInBytes = ASCIIEncoding.GetBytes(givenString);
            foreach (var currentByte in resultInBytes)
            {
                result.Append(string.Format("0x{0:X} ", currentByte));
            }
            return result.ToString();
        }

        public static string ConvertToWindows1251(this string givenString)
        {
            StringBuilder result = new StringBuilder();
            Encoding Windows1251Encoding = Encoding.GetEncoding("Windows-1251");
            byte[] resultInBytes = Windows1251Encoding.GetBytes(givenString);
            foreach (var currentByte in resultInBytes)
            {
                result.Append(string.Format("0x{0:X} ", currentByte));
            }
            return result.ToString();
        }
    }
}
